<template>
	<view>
		<!-- 地址 -->
		<navigator class="address-section">
			<view class="order-content">
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{order.address.ship_name}}</text>
						<text class="mobile">{{order.address.ship_mobile}}</text>
					</view>
					<text class="address">{{order.address.ship_area}}{{order.address.ship_addr}} </text>
				</view>
				<!-- <text class="yticon icon-you"></text> -->
			</view>

			<image class="a-bg" src=""></image>
		</navigator>

			<view class="goods-section">
				<view class="g-header b-b">
					<!-- <image class="logo" :src="order.shop_logo"></image> -->
					<text class="name">平台自营</text>
				</view>
				<!-- 商品列表 -->
				<block v-for="(item, gindex) in order.goods" :key="gindex">
					<view class="g-item">
						<image :src="item.product_image"></image>
						<view class="right">
							<text class="title clamp">{{item.goods_name}}</text>
							<text class="spec">{{item.spec}}</text>
							<view class="price-box">
								<text class="price">￥{{item.retail_price}}</text>
								<text class="number">x {{item.num}}</text>
							</view>
							<button v-if="(order.status==3 || order.status==6) && order.after_status == 0" class="return" @click="returns(order.oid, item.id)">申请售后</button>
							<button v-if="order.after_status > 0" class="return" style="color:red">{{order.after_status == 1 ? '售后中' : '售后完成'}}</button>
						</view>
					</view>
				</block>
			</view>
		
		<!-- 金额明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">商品金额</text>
				<text class="cell-tip">￥{{order.goods_price}}</text>
			</view>
			<view class="yt-list-cell b-b" >
				<text class="cell-tit clamp">优惠金额</text>
				<text class="cell-tip red">-￥{{order.discount_price}}</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">运费</text>
				<text class="cell-tip">￥{{order.distribution_price}}</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">实付</text>
				<text class="cell-tip">￥{{order.price}}</text>
			</view>
			<view class="orderInfo">
				<view class="cell-tit">订单信息</view>
				<view class="info">订单编号：{{order.oid}}</view>
				<view class="cell-tit">订单动态</view>
				<uni-steps :options="list2" active-color="#007AFF" :active="active" direction="column" />
				<!-- <view class="cell-tit">订单信息</view>
				<view class="info">订单编号：{{order.oid}}</view>
				<view class="info" v-if="order.create_time">下单时间：{{order.create_time}}</view>
				<view class="info" v-if="order.order_pay_time">支付时间：{{order.order_pay_time}}</view>
				<view class="info" v-if="order.delivery_time">发货时间：{{order.delivery_time}}</view>
				<view class="info" v-if="order.confirm_time">完成时间：{{order.confirm_time}}</view>
				<view class="info" v-if="order.cancel_time">取消时间：{{order.cancel_time}}</view> -->
			</view>
		</view>
		
		<!-- 底部 -->
		<view class="footer" v-if="order.status == 0">
			<button class="action-btn" @click="cancelOrder(order.oid)">取消订单</button>
			<button class="action-btn recom" @click="pay(order.oid)">立即支付</button>
		</view>
	
		<view class="footer" v-else-if="order.status == 2">
			<!-- <button class="action-btn" @click="returns(order.id)">申请售后</button> -->
			<button class="action-btn recom" @click="confirmOrder(order.oid)">确认收货</button>
		</view>
		<view class="footer" v-else-if="order.status == 3">
			<!-- <button class="action-btn" @click="returns(order.id)">申请售后</button> -->
			<button class="action-btn recom" @click="evaluationOrder(order.oid)">立即评价</button>
		</view>
		<!-- <view class="footer"  v-else-if="order.status == 4">
			<button class="action-btn recom">售后中</button>
		</view> -->
		<view class="footer"  v-else-if="order.status == 6">
			<button class="action-btn recom  action-finash">已完成</button>
		</view>
		<view class="footer" v-else-if="order.status == 5">
			<button class="action-btn recom">已取消</button>
		</view>
	</view>
</template>

<script>
	import { mapState } from 'vuex';
	export default {
		data() {
			return {
				oid:'',
				order:{},
				list2:[],
				active: 1,
			}
		},
		computed:{
			...mapState(['hasLogin','userInfo'])
		},
		onLoad(option){
			if(option.oid){
				this.oid = option.oid
				this.loadData(option.oid)
			}else{
				this.$api.msg('缺少参数！')
				setTimeout(()=>{
					uni.navigateBack({
						delta:1
					})
				},1500)
			}
		},
		methods: {
			loadData:function(oid){
				var that = this
				let _param = {
					token:that.userInfo.token,
					oid:oid
				};
				that.$api.getUrl(that.$api._api.ApiOrderDetail,_param,function(res){
					that.order = res
					
					if(res.create_time){
						that.list2.push({title:'用户下单','desc':res.create_time})
					}
					
					if(res.order_pay_time){
						that.list2.push({title:'用户支付','desc':res.order_pay_time})
					}
					
					if(res.delivery_time){
						that.list2.push({title:'平台发货','desc':res.delivery_time})
					}
					
					if(res.confirm_time){
						that.list2.push({title:'用户签收','desc':res.confirm_time})
					}
					
					if(res.cancel_time){
						that.list2.push({title:'用户取消','desc':res.cancel_time})
					}
					
					that.active = that.list2.length
					
					//console.log(
				})
			},
			cancelOrder(oid){
				this.$api.loading(true, "请稍后")
				
				let _param = {
					oid:oid,
					token:this.userInfo.token,
				};
				let that = this;
				that.$api.postUrl(that.$api._api.ApiOrderCancel,_param,function(res){
					that.$api.loading(false)
					that.$api.msg('取消成功')
					that.loadData(oid)
				})
				
			},
			pay(oid){
				uni.redirectTo({
					url: '/pages/user/money/pay?oid='+oid
				})
			},
			confirmOrder(oid){
				this.$api.loading(true, "请稍后")
				
				let _param = {
					oid:oid,
					token:this.userInfo.token,
				};
				let that = this;
				that.$api.postUrl(that.$api._api.ApiOrderConfirm,_param,function(res){
					that.$api.loading(false)
					that.$api.msg('确认收货成功')
					that.loadData()
				})
			},
			//申请售后
			returns(oid, id){
				uni.navigateTo({
					url:'/pagesA/retreat/retreat?oid=' + oid + '&id=' + id
				})
			},
			//立即评价
			evaluationOrder(oid){
				uni.navigateTo({
					url:'/pagesA/lack/comRele/comRele?oid='+oid
				})
			},
		}
	}
</script>

<style lang="scss">
	.orderInfo{
		padding: 5px 16px 5px 22px;
		.cell-tit{margin: 20rpx 0 40rpx 0;font-size:30rpx;}
		.info{font-size: 26rpx;color:#999;margin-top: 20rpx;}
	}
	
	page {
		background: $page-color-base;
		padding-bottom: 100rpx;
	}

	.address-section {
		padding: 30rpx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}

		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90rpx;
			color: #888;
			font-size: 44rpx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 28rpx;
			color: $font-color-dark;
		}

		.name {
			font-size: 34rpx;
			margin-right: 24rpx;
		}

		.address {
			margin-top: 16rpx;
			margin-right: 20rpx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32rpx;
			color: $font-color-light;
			margin-right: 30rpx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5rpx;
		}
	}

	.goods-section {
		margin-top: 16rpx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84rpx;
			padding: 0 30rpx;
			position: relative;
		}

		.logo {
			display: block;
			width: 50rpx;
			height: 50rpx;
			border-radius: 100px;
		}

		.name {
			font-size: 30rpx;
			color: $font-color-base;
			margin-left: 24rpx;
		}

		.g-item {
			display: flex;
			margin: 20rpx 30rpx;

			image {
				flex-shrink: 0;
				display: block;
				width: 140rpx;
				height: 140rpx;
				border-radius: 4rpx;
			}

			.right {
				flex: 1;
				padding-left: 24rpx;
				overflow: hidden;
			}

			.title {
				font-size: 30rpx;
				color: $font-color-dark;
			}

			.spec {
				font-size: 26rpx;display: block;
				color: $font-color-light;margin-top:6rpx;
			}

			.price-box {
				display: flex;
				align-items: center;
				font-size: 32rpx;
				color: $font-color-dark;
				padding-top:20rpx;

				.price {
					margin-bottom: 4rpx;color:#f04447;flex: 1;
				}
				.number{
					font-size: 26rpx;
					color: $font-color-base;
					margin-left: 20rpx;
				}
			}
			.return{
				width: 130rpx;
				height: 55rpx;
				margin: 0;
				padding: 0;
				text-align: center;
				line-height: 55rpx;
				font-size: $font-sm;
				color: $font-color-dark;
				background: #fff;
				border-radius: 100px;
				&:after{
					border-radius: 100px;
				}
				&.recom{
					background: #fff9f9;
					color: $base-color;
					&:after{
						border-color: #f7bcc8;
					}
				}
			}
			.step-box {
				position: relative;
			}
		}
	}
	.yt-list {
		margin-top: 16rpx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10rpx 30rpx 10rpx 40rpx;
		line-height: 70rpx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30rpx;
		}

		.cell-icon {
			height: 32rpx;
			width: 32rpx;
			font-size: 22rpx;
			color: #fff;
			text-align: center;
			line-height: 32rpx;
			background: #f85e52;
			border-radius: 4rpx;
			margin-right: 12rpx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24rpx;
			color: $font-color-light;
			margin-left: 8rpx;
			margin-right: -10rpx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26rpx;
			color: $font-color-light;
			margin-right: 10rpx;
		}

		.cell-tip {
			font-size: 26rpx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}
			&.red{
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90rpx;
			}
		}

		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}
	
	/* 支付列表 */
	.pay-list{
		padding-left: 40rpx;
		margin-top: 16rpx;
		background: #fff;
		.pay-item{
			display: flex;
			align-items: center;
			padding-right: 20rpx;
			line-height: 1;
			height: 110rpx;	
			position: relative;
		}
		.icon-weixinzhifu{
			width: 80rpx;
			font-size: 40rpx;
			color: #6BCC03;
		}
		.icon-alipay{
			width: 80rpx;
			font-size: 40rpx;
			color: #06B4FD;
		}
		.icon-xuanzhong2{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60rpx;
			height: 60rpx;
			font-size: 40rpx;
			color: $base-color;
		}
		.tit{
			font-size: 32rpx;
			color: $font-color-dark;
			flex: 1;
		}
	}
	
	.footer{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 90rpx;
		justify-content:flex-end;
		font-size: 30rpx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0,0,0,.1);
		.action-btn{
			width: 160rpx;
			height: 60rpx;
			margin: 0;
			margin-left: 24rpx;
			padding: 0;
			text-align: center;
			line-height: 60rpx;
			font-size: $font-sm + 2rpx;
			color: $font-color-dark;
			background: #fff;
			border-radius: 100px;
			&:after{
				border-radius: 100px;
			}
			&.recom{
				background: #fff9f9;
				color: $base-color;
				&:after{
					border-color: #f7bcc8;
				}
			}
		}
	}
	.action-btn.recom.action-finash{background: none;color:#000}
</style>
